﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace CarPCBATest.Procedure
{
    internal class PowerDoDescConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            FieldInfo field = null;
            if(parameter.ToString() == "powerdo")
            {
                DOFunction tmp = (DOFunction)value;
                field = tmp.GetType().GetField(value.ToString());
            }
            else if(parameter.ToString() == "do")
            {
                DODefine tmp = (DODefine)value;
                field = tmp.GetType().GetField(value.ToString());
            }
            else if (parameter.ToString() == "di")
            {
                DIDefine tmp = (DIDefine)value;
                field = tmp.GetType().GetField(value.ToString());
            }

         
            if (field != null)
            {
                DescriptionAttribute attribute = (DescriptionAttribute)Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute));
                if (attribute != null)
                {
                    return attribute.Description;
                }
            }

            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
